#include <p33fxxxx.h>
#include <adc.h>

void ADC_initial(void)
{
	ADCON	=0X1004;		// ENABLE AD CONVERT AND ACLK / 5 =24M
	ADPCFG	=0XFFCC;		// AN5, AN4, AN1, AN0 <= ON 0xffc0
	ADCPC0	=0X0404;		// AN3,2,1,0 AS TRIGGER SOURCE, PWM1 AS OUTPUT
	ADCPC1	=0X0606;		// AN5 & AN4 AS TRIGGER SOURCE, PWM1 AS OUTPUT
	
	IPC27	=0X0200;		// 0x0200 AD PAIR 0(AN1,AN0) 
							// WITH INTERRUPT PRIORITY 002
	IFS6bits.ADCP0IF=0;		// CLEAR ADCP0 INTTERRUPT FLAG
	IFS6bits.ADCP1IF=0;		// CLEAR ADCP1 INTERRUPPT FLAG
	IEC6bits.ADCP0IE=1;		// ENABLE ADCP0 INTERRUPT
	IEC6bits.ADCP1IE=1;		// ENABLE ADCP1 INTERRUPT
	
	delay50ms();
	IFS7bits.ADCP2IF=0;		// CLEAR INTERRUPT FLAG OF AD PAIR 2
	IEC7bits.ADCP2IE=1;		// ENABLE INTERRUPT ON AD PAIR 2


	ADCONbits.ADON=1;		// AD ON

} 
